package com.ihg.hiex.entity.user;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;
import com.ihg.hiex.entity.data.conference.ConferenceRoom;
import com.ihg.hiex.entity.session.participator.SessionFacilitator;

/**
 * 管理员
 * 
 * @author downpour
 *
 */
@Entity
@Table(name = "admin_user")
@PersistentFormat
public class Administrator {

    @Id
    @GeneratedValue
    private Long id;

    /** 对应Account */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Account account;

    /** 姓名 */
    private String name;

    /** 邮箱 */
    private String email;

    /**
     * 角色
     * 
     * ADMIN - 管理员 FACILITATOR - 主持人
     */
    private String role;

    /** 关联会议室(WebEx) */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private ConferenceRoom conferenceRoom;

    /** 电话号码 */
    private String telephone;

    /** 地址 */
    private String location;

    private Date createTime;

    private Date lastModifyTime;

    @Column(name = "is_disabled")
    private boolean disabled;

    /**
     * The default constructor.
     */
    public Administrator() {
    }

    /**
     * construct Administrator by facilitator
     * 
     * @param account
     * @param facilitator
     * @param conferenceRoom
     */
    public Administrator(Account account, SessionFacilitator facilitator, ConferenceRoom conferenceRoom) {
        this.account = account;
        this.name = facilitator.getName();
        this.email = facilitator.getEmail().toLowerCase();
        this.telephone = facilitator.getMobile();
        this.role = Role.FACILITATOR.toString();
        this.conferenceRoom = conferenceRoom;
        this.createTime = new Date();
        this.lastModifyTime = createTime;
    }

    /**
     * initialize
     * 
     * @param account
     * @param conferenceRoom
     * @return
     */
    public Administrator initialize(Account account, ConferenceRoom conferenceRoom) {
        this.email = this.email.toLowerCase();
        this.account = account;
        this.role = Role.ADMIN.toString();
        this.conferenceRoom = conferenceRoom;
        this.createTime = new Date();
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * 
     * @param account
     * @return
     */
    public Administrator initialize(Account account) {
        this.email = this.email.toLowerCase();
        this.account = account;
        this.role = Role.COACH.toString();
        this.createTime = new Date();
        this.lastModifyTime = new Date();
        this.disabled = false;
        return this;
    }

    /**
     * disable user
     * 
     * @return
     */
    public Administrator disable() {
        this.disabled = true;
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @return
     */
    public Administrator edit() {
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @return
     */
    public boolean hasConferenceRoom() {
        return this.conferenceRoom != null;
    }

    /**
     * @param conferenceRoom
     * @return
     */
    public Administrator edit(ConferenceRoom conferenceRoom) {
        this.conferenceRoom = conferenceRoom;
        return this;
    }

    /**
     * 
     * @return
     */
    public String getIdString() {
        return id.toString();
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the account
     */
    public Account getAccount() {
        return account;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @return the role
     */
    public String getRole() {
        return role;
    }

    /**
     * @return the conferenceRoom
     */
    public ConferenceRoom getConferenceRoom() {
        return conferenceRoom;
    }

    /**
     * @return the telephone
     */
    public String getTelephone() {
        return telephone;
    }

    /**
     * @return the location
     */
    public String getLocation() {
        return location;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param account
     *            the account to set
     */
    public void setAccount(Account account) {
        this.account = account;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param email
     *            the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @param role
     *            the role to set
     */
    public void setRole(String role) {
        this.role = role;
    }

    /**
     * @param conferenceRoom
     *            the conferenceRoom to set
     */
    public void setConferenceRoom(ConferenceRoom conferenceRoom) {
        this.conferenceRoom = conferenceRoom;
    }

    /**
     * @param telephone
     *            the telephone to set
     */
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    /**
     * @param location
     *            the location to set
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * @param createTime
     *            the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastModifyTime
     *            the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param disabled
     *            the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
